package com.pattern.observer;

import java.util.ArrayList;
import java.util.List;

public class Author {

    private final List<FansObserver> fansObservers = new ArrayList<>();

    public void addObserver(FansObserver fansObserver) {
        fansObservers.add(fansObserver);
    }

    public void removeObserver(FansObserver fansObserver) {
        fansObservers.remove(fansObserver);
    }

    public void sendMessage(String message){
        System.out.println("作者发送消息："+message);
        notifyAllFans(message);
    }

    public void notifyAllFans(String message) {
        for (FansObserver fansObserver : fansObservers) {
            fansObserver.receive(message);
        }
    }


}
